﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WinFormsAppTest.Service
{
    internal class SearchBarService
    {
        //需要配合着SearchBarClass或者DataGridView的列名以及界面搜素栏的文本进行使用

        //需要传入的值有，需要输出到的表格UserdataGridView，搜素的复选框searchcomboBox,搜素的内容searchtextBox
        public void SearchUser(DataGridView UserdataGridView, ComboBox searchcomboBox, TextBox searchtextBox)
        {

            if (string.IsNullOrWhiteSpace(searchtextBox.Text)
                || searchcomboBox.SelectedItem == null)//判断复选框是否选中
            {
                UserdataGridView.Rows.Clear();
                DataGridViewClass dataGridView = new DataGridViewClass();
                UserdataGridView = dataGridView.GetUsersData(UserdataGridView);
            }
            else
            {
                string combox = searchcomboBox.SelectedItem.ToString();
                UserdataGridView.Rows.Clear();
                if (int.TryParse(searchtextBox.Text, out int number)
                    && combox == "用户id")
                {
                    if (number != 0 && searchtextBox.Text != "请输入搜索内容")
                    {
                        DataGridViewClass dataGridView = new DataGridViewClass();
                        UserdataGridView = dataGridView.GetUserDataById(UserdataGridView, number);
                    }
                    else
                    {
                        DataGridViewClass dataGridView = new DataGridViewClass();
                        UserdataGridView = dataGridView.GetUsersData(UserdataGridView);
                    }

                }
                else if (combox == "用户名")
                {
                    if (searchtextBox.Text != "" && searchtextBox.Text != "请输入搜索内容")
                    {
                        DataGridViewClass dataGridView = new DataGridViewClass();
                        UserdataGridView = dataGridView.GetUserDataByName(UserdataGridView, searchtextBox.Text);
                    }
                    else
                    {
                        DataGridViewClass dataGridView = new DataGridViewClass();
                        UserdataGridView = dataGridView.GetUsersData(UserdataGridView);
                    }

                }
                else
                {
                    DataGridViewClass dataGridView = new DataGridViewClass();
                    UserdataGridView = dataGridView.GetUsersData(UserdataGridView);
                }
            }
        }


    }
}
